package cn.driver.coach.mapper;


import cn.driver.common.pojo.Coach;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CoachMapper {

    /**
     * 查询所有列表
     *
     * @return
     */
    @Select("SELECT id, account, PASSWORD, coachName, age, gender, avatar, tel, introduse, state FROM driving_school.coach")
    List<Coach> getCoachList();

    /**
     * 增加教练
     *
     * @param coach
     * @return
     */
    @Insert("INSERT INTO driving_school.coach" +
            "(account, `password`, coachName, age, gender, tel, introduse)" +
            "VALUES" +
            "( #{account}, #{password}, #{coachName}, #{age}, #{gender}, #{tel}, #{introduse})")
    int addCoach(Coach coach);

    /**
     * 删除教练
     *
     * @param id
     * @return
     */
    @Delete("DELETE FROM driving_school.coach WHERE id = #{id}")
    int deleteCoach(int id);

    /**
     * 修改
     *
     * @param coach
     * @return
     */
    @Update({"<script>",
            "update coach",
            "   <set>",
            "       <if test='account != null and account != \"\"'>`account` = #{account},</if>",
            "       <if test='password != null and password != \"\"'>`password` = #{password},</if>",
            "       <if test='coachName != null and coachName != \"\"'>`coachName` = #{coachName},</if>",
            "       <if test='age != null'>`age` = #{age},</if>",
            "       <if test='gender != null'>`gender` = #{gender},</if>",
            "       <if test='avatar != null and avatar != \"\"'>`avatar` = #{avatar},</if>",
            "       <if test='tel != null and tel != \"\"'>`tel` = #{tel},</if>",
            "       <if test='introduse != null and introduse != \"\"'>`introduse` = #{introduse},</if>",
            "       <if test='state != null and state != \"\"'>`state` = #{state}</if>",
            "   </set>",
            "where id = #{id}",
            "</script>"})
    int updateCoach(Coach coach);


    @Select("SELECT * FROM coach WHERE coachName LIKE '%${coachName}%'")
    List<Coach> mohuList(String coachName);

}
